import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

//传递数据
typedef void AGTextFieldCallBack(String content);
typedef void AGTextFieldControllerCallBack(TextEditingController content);
//输入框
class AccountEdit3Text extends StatefulWidget {
  final AGTextFieldCallBack contentStrCallBack;
  final AGTextFieldControllerCallBack controllerCallBack;
  final String hitText;
  final  String icon ;
  final  String defaultText ;
  final bool pwd;
  final int maxLength;
  final inputColor;
  final TextAlign textAlign;
  final TextInputType keyboardType;

  AccountEdit3Text(
      {required  Key key,

      required this.contentStrCallBack,
        required this.controllerCallBack,
        this.textAlign = TextAlign.start,
        this.defaultText = '',
      this.hitText = '请输入',
       this.icon='',
        this.inputColor=0,
        this.keyboardType = TextInputType.text,
      this.pwd = false,this.maxLength=10000,})
      : super(key: key);

  @override
  _AccountEditTextState createState() => _AccountEditTextState();
}

String _inputAccount = "";
bool _isShowDelete = false;
final TextEditingController _controller = TextEditingController();
class _AccountEditTextState extends State<AccountEdit3Text> {
  @override
  void dispose() {
    super.dispose();
  }

  @override
  void initState() {
    super.initState();
    _inputAccount = '';
    _controller.text = widget.defaultText;
    _inputAccount = widget.defaultText;
    widget.controllerCallBack (_controller) ;
  }


  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child: Theme(
        data: ThemeData(
            highlightColor: Colors.transparent,
            splashColor: Colors.transparent), //去除水波纹效果
        child: Container(
          alignment: Alignment.bottomCenter,
          padding: EdgeInsets.only(
          ),
          // margin: EdgeInsets.only(bottom: 30.0),
          decoration: BoxDecoration(
            color: widget.inputColor==0?Colors.white:Color(widget.inputColor),
            borderRadius: BorderRadius.circular(6.0),
          ),
          child: TextField(

            textAlignVertical: TextAlignVertical.center,
            textAlign: widget.textAlign,
            controller: _controller,
            style: TextStyle(color: Color(0xff000000), fontSize: 16.sp),
            keyboardType: widget.keyboardType,
            enableInteractiveSelection: false,
            decoration: InputDecoration(
              contentPadding: EdgeInsets.all(0),
              icon: widget.icon != ''
                  ? Image.asset(
                      widget.icon,
                      width: 14.h,
                      height: 16.h,
                    )
                  : null,
              border: OutlineInputBorder(borderSide: BorderSide.none),
              counterText: "",
              hintText: widget.hitText,
              labelStyle: TextStyle(color: Color(0xFFB3B3C6), fontSize: 14.sp),
              // contentPadding: EdgeInsets.symmetric(vertical: 0),
              hintStyle: TextStyle(color: Color(0xFFB3B3C6), fontSize: 14.sp),

            ),
            onChanged: (str) {
              setState(() {
                _inputAccount = str;
                _isShowDelete = _inputAccount.isNotEmpty;
                widget.contentStrCallBack(_inputAccount);
              });
            },
            // keyboardType: TextInputType.number,
            maxLength: widget.maxLength,
            maxLines: 1,
            obscureText: widget.pwd,
          ),
        ),
      ),
    );
  }
}
